<?php
class p_search extends page_controllor 
{
    public function __construct($get_param)
    {
        $this->__need_login = true;
        parent::__construct($get_param);
    }
    public function run()
    {
        $type = $this->get_input(0);
    	$key = urldecode($this->get_input(1));
        
        
        $oProduct = K::load_mod('product');
        $oProduct->search_by_name($total , $this->__isLangEng , $key , $type) or $this->busy();
        $aProduct = $oProduct->get_data();
        if(count($aProduct) > 0)
        {
            foreach ($aProduct as $k => $row)
            {
                $aProduct[$k]['name'] = $this->__isLangEng ? K_str::un_html($row['eng_name']) : K_str::un_html($row['name']);
                $aProduct[$k]['cover_url'] = product2coverpath($row['id'] , true);
                $aProduct[$k]['product_url'] = '/product/show/'.$row['sn'];
            }
        }
        
     
        $oArraytree = new lib_arraytree(array());
        $oArraytree->restart(k::config('product_class'));
        $namefield = $this->__isLangEng ? 'eng_name' : 'name';
        $out_data['product_class'] = $oArraytree->get_id2field( $namefield );
        $out_data['total'] = $total;
        $out_data['type'] = $type;
        $out_data['key'] = $key;
        $out_data['products'] = $aProduct;
        
        $this->set_page_title($this->__lang['gTitle_p_productList'].'_'.$this->__lang['gTitle_page_title']);
        $this->output('product_search' , $out_data);
    }
}
?>